#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<cmath>
using namespace std;

int main()
{
	int  a = 0, b = 1, c = 1;

	int n; 
	cin >> n;

	while (c < n)
	{
		a = b;
		b = c; 
		c = a + b;
	}

	cout << min(c - n, n - b) << endl;
	return 0;
}